<template>
	<view class="page_edu">
		<view class="login-box" style="width: 50px;">
			<text v-if="!userName" @click="gologin">登陆</text>
			<text v-else @click="out">退出</text>
		</view>
		<u-swiper :list="bannerList" :circular="true" height="500" @click="goLink"></u-swiper>
	<!-- 	<swiper class="" circular autoplay style="width: 100%;height: 600rpx;">
			<swiper-item v-for="(item, index) in bannerList" :key="index" class="carousel-item" @click="goLink(item.imgsrc)">
				<image :src="$api.json('baseUrl')+'/upload/'+ item.imgurl" style="width: 100%;height: 400rpx;" />
			</swiper-item>
		</swiper> -->
		<view class="page_content catebox">
			<scroll-view scroll-x="true">
				<view class="menu">
					<view class="itembox" :key="'menu_'+i" v-for="(it,i) in menus" @click="goPath(it.path)">
						<view class="img_view" :style="{background: it.bg}">
							<image :src="it.icon" class="image"></image>
						</view>
						<text class="txt">{{it.txt}}</text>
					</view>
				</view>
			</scroll-view>
		</view>
		<u-card :title="emp.title" :sub-title="emp.subTitle" :thumb="emp.icon" margin="0">
			<view slot="body" v-if="empList.length<1">
				<u-empty mode="list" ></u-empty>
			</view>
			<view class="u-flex yu-start" slot="body" v-else style="overflow-x: auto;">
				<view class="u-flex yu-flex-col emp-item" v-for="(e,i) in empList" :key="i" @click="goEmp(e)">
					<u-avatar size="120" mode="square" :src="$api.json('baseUrl')+ '/upload/' + e.empheadimg"></u-avatar>
					<view class="yu-color-3 yu-bold u-line-1 u-text-center u-p-b-10 u-p-t-10 u-line-1" style="width: 100%;">{{e.empname}}</view>
					<view class="u-line-1" style="width: 100%;padding:0 10rpx;">{{e.empinfo}}</view>
				</view>
			</view>
		</u-card>
		<u-card :title="band.title" :sub-title="band.subTitle" :thumb="band.icon" margin="10rpx 0 20rpx 0">
			<view slot="body" v-if="noticeList.length<1">
				<u-empty mode="list" ></u-empty>
			</view>
			<view class="" slot="body" v-else>
			<u-cell-item icon="volume-up" :title="el.title.length>7?el.title.slice(0,7)+'...':el.title" :value="el.createtime" v-for="(el, i) in noticeList" @click="goNotice(el)"></u-cell-item>
			</view>
		</u-card>
	</view>
</template>

<script>
	import uniSegmentedControl from "@/components/uni-segmented-control/uni-segmented-control.vue"
	// import uniFab from '@/components/uni-fab/uni-fab.vue';
	export default {
		components: {
			// uniFab
		},
		data() {
			return {
				VideoSrc: '',
				getVideoUrl: '',


				title: '',
				emp: {
					title: '师资力量',
					subTitle: '',
					icon: '../../static/userimg/emp.png'
				},
				band: {
					title: '公告',
					subTitle: '',
					icon: '../../static/userimg/band.png'
				},
				content: [{
					text: '上传视频',
					iconPath: '../../static/upload.png'
				}, ],
				pattern: {
					backgroundColor: 'rgba(204,204,204,0.1)',
					color: '#fff',
					buttonColor: 'rgba(56,171,25,0)',
				},
				current: 0,
				tabs: ['推荐视频', '我的视频'],
				userImg: '',
				userName: '',
				uuu: '../../static/live.png',
				bannerList: [],
				VideoList: [],
				VideoList2: [],
				empList: [],
				noticeList: [],
				titleNViewBackground: 'background:#0bc99d',
				menus: [{
						bg: 'linear-gradient(0deg,rgba(0, 85, 0, 1.0),rgba(255, 147, 38, 1.0))',
						icon: '/static/cateimg/xufree.png',
						txt: '报名/续费',
						isFree: true,
						path: '/pages/joinClass/joinClass'
					},
					{
						bg: 'linear-gradient(0deg,rgba(170, 255, 0, 1.0),rgba(255, 170, 255, 1.0))',
						icon: '/static/cateimg/shop.png',
						txt: '商城',
						isFree: false,
						path: '/pages/shop/shop'
					},
					{
						bg: 'linear-gradient(0deg,rgba(85, 0, 0, 1.0),rgba(77, 95, 37, 1.0))',
						icon: '/static/cateimg/uploadVideo.png',
						txt: '视频中心',
						isFree: true,
						path: '/pages/video/video',
						// path: '/pages/Dd-DouYin/Dd-DouYin',
						
					},
					{
						bg: 'linear-gradient(0deg,rgba(255, 170, 127, 1.0),rgba(170, 255, 127, 1.0))',
						icon: '/static/cateimg/classList.png',
						txt: '课表',
						isFree: true,
						path: '/pages/lession/lession'
					},
					{
						bg: 'linear-gradient(0deg,rgba(255, 170, 0, 1.0),rgba(170, 255, 255, 1.0))',
						icon: '/static/cateimg/myInfo.png',
						txt: '我的',
						isFree: true,
						path: '/pages/profile/profile'
					}
					// {
					// 	bg: 'linear-gradient(0deg,rgba(57, 255, 226, 1.0),rgba(240,184,27,1))',
					// 	icon: '/static/question_bank.png',
					// 	txt: '点到',
					// 	isFree: true,
					// 	path: '/pages/sign/sign'
					// },
				]
			}
		},
		onLoad() {
			this.init()
		},
		onShow() {
			uni.getStorage({
				key: 'userName',
				success: (res) => {
					this.userName = res.data
					console.log(this.userName, 123);
				}
			});
		},
		onPullDownRefresh() {
			this.getNotice()
			this.getBanner()
			this.getEmp()
		},
		methods: {
			init(){
				this.$http('/init', {tcode:this.$api.json('tcode')}, (res) => {
					if(res.resultCode === '000000'){
						this.getNotice()
						this.getBanner()
						this.getEmp()
					}
				})
			},
			goLink(val) {
				const item = this.bannerList[val]
				if (item.imgsrc) {
					window.open(item.imgsrc, '_self')
				}
			},
			getEmp() {
				this.$http('/employee/findEmp', {}, (res) => {
					console.log(res, 66);
					this.empList = res.data
					uni.stopPullDownRefresh()
				})
			},
			getNotice() {
				this.$http('/notice/findNotice', {}, (res) => {
					this.noticeList = res.data
				})
			},
			goEmp(val) {
				sessionStorage.setItem('empDetail', JSON.stringify(val))
				uni.navigateTo({
					url: '/pages/empDetail/empDetail'
				})
			},
			goNotice(val) {
				sessionStorage.setItem('noticeDetail', JSON.stringify(val))
				uni.navigateTo({
					url: '/pages/noticeDetail/noticeDetail'
				})
			},
			getBanner() {
				uni.request({
					method: 'POST',
					url: this.$api.json('baseUrl') + '/config/getIndexImg', //仅为示例，并非真实接口地址。
					data: {},
					success: (res) => {
						if (res.data.resultCode == '000000') {
							const blist = res.data.data
							this.bannerList = blist.map(e=>{
								return {
									image: this.$api.json('baseUrl')+'/upload/'+ e.imgurl,
									imgsrc: e.imgsrc
								}
							})
						} else {
							this.$api.msg(res.data.resultInfo || res.data.error);
						}
					}
				});
			},
			goPath(path) {
				if (path) {
					uni.navigateTo({
						url: path
					})
				}
			},
			gologin() {
				uni.navigateTo({
					url: '/pages/login/login'
				})
			},
			out() {
				uni.request({
					method: 'POST',
					url: this.$api.json('baseUrl') + '/login/h5out', //仅为示例，并非真实接口地址。
					data: {},
					success: (res) => {
						console.log(res);
						if (res.data.resultCode == '000000') {
							uni.setStorage({
								key: 'userName',
								data: '',
								success: () => {
									this.$api.msg('退出成功！')
									this.userName = ''
								}
							});
						} else {
							this.$api.msg(res.data.resultInfo || res.data.error);
						}
					}
				});
			}
		}
	}
</script>

<style>
	.uni-video {
		height: 190px !important;
	}

	page {
		width: 100%;

		/* background-color: #fff; */
	}
</style>
<style lang="scss" scoped>
	@function realSize($args) {
		@return $args / 1.5;
	}

	.page_edu {
		width: 100%;
		position: relative;

		.login-box {
			position: absolute;
			z-index: 2;
			top: 30rpx;
			left: 30rpx;
		}
	}

	.page_content {
		width: 100%;

		.menu {
			width: 100%;
			padding: 0 20rpx;
			margin: 10rpx 0;
			height: realSize(176px);
			background: rgba(255, 255, 255, 1);
			box-shadow: 0px 10px 10px 0px rgba(0, 161, 124, 0.1);
			border-radius: 40rpx 40rpx 10rpx 10rpx;
			display: flex;
			justify-content: space-around;

			.itembox {
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				width: 20%;

				.img_view {
					width: 100rpx;
					height: 100rpx;
					border-radius: 60rpx;
					display: flex;
					align-items: center;
					justify-content: center;

					.image {
						width: 60rpx;
						height: 60rpx;
					}
				}

				.txt {
					margin-top: 5px;
					font-size: 14px;
					color: rgba(51, 51, 51, 1);
				}
			}
		}

	}

	.catename {
		// width: 60%;
		border-radius: 20rpx 20rpx 0 0;
		padding: 40rpx 20rpx 0 20rpx;
		font-size: 40rpx;
		background-color: #FFF;
	}

	.catebox {
		margin-top: -40rpx;
	}
	.emp-item{
		width: 20%;
	}
	.slider {
		// white-space:;
		width: 100%;
		background-color: white;
		padding: 30rpx 20rpx;
		box-sizing: border-box;
	}
</style>
